package com.scisoft.scan.control.pack;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.scisoft.scan.dy.R;
import com.scisoft.scan.data.pack.PackDetailBean;

import java.util.List;

public class PackDetailAdapter extends BaseAdapter {
    private List<PackDetailBean> packDetailBeanList;//数据源
    private LayoutInflater mInflater;//布局装载器对象
    private String flag;//状态
    private int currentState;//1 未打包 2 已打包

    public PackDetailAdapter(String flag, int currentState, List<PackDetailBean> packDetailBeanList, Context context) {
        this.packDetailBeanList = packDetailBeanList;
        mInflater = LayoutInflater.from(context);
        this.flag = flag;
        this.currentState = currentState;
    }

    @Override
    public int getCount() {
        //return返回的是int类型，也就是页面要显示的数量。
        return packDetailBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return packDetailBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局文件转化为View对象
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_packdetail, null);
        }
        //标题
        TextView tv_title = convertView.findViewById(R.id.tv_title);
        //信息
        TextView tv_subtitle = convertView.findViewById(R.id.tv_subtitle);
        //统计明细
        TextView tv_detail = convertView.findViewById(R.id.tv_detail);
        //时间
        TextView tv_optime = convertView.findViewById(R.id.tv_optime);

        //获取相应索引的ItemBean对象
        PackDetailBean bean = packDetailBeanList.get(position);

        //设置控件的对应属性值
        tv_title.setText(bean.partCode + " " + bean.partName);
        tv_subtitle.setText(bean.manufacturer + " " + bean.manufacturerName);


        tv_optime.setText(bean.optime);

        if ("3".equals(flag)) {
            tv_detail.setText("总数:" + bean.totalCount + " 本箱打包数: " + bean.packedCount);
        } else {
            if (currentState == 1) {
                //未打包
                tv_detail.setText("总数:" + bean.totalCount + "    已打包总数: " + bean.packedCount + "    待打包数:" + bean.notpackCount);
            } else {
                //已打包
                tv_detail.setText("总数:" + bean.totalCount + "    本箱打包数: " + bean.packedCount + "    已打包总数: " + bean.packingCount + "    待打包数:" + bean.notpackCount);
            }
        }
        return convertView;
    }
}
